package com.xdkj.util;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CreateBucketRequest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2021/11/29 9:52
 */
public class OssClientUtil {
    public static final String ENDPOINT="oss-cn-beijing.aliyuncs.com";
    public static final String BUCKETURL="xdkj-cs.oss-cn-beijing.aliyuncs.com";
    public static final String BUCKETNAME="xdkj-cs";
    public static final String ACCESSKEYID="LTAI5t6WXeKrwvxLWjktjEcG";
    public static final String ACCESSKEYPASSWORD="X715kIZBHgET0i4WUDG4FLPOGvw92r";

    public static OSSClient getOssClient(){
        OSSClient ossClient = new OSSClient(ENDPOINT, ACCESSKEYID, ACCESSKEYPASSWORD);
        if (!ossClient.doesBucketExist(BUCKETNAME)) {
            CreateBucketRequest createBucketRequest = new CreateBucketRequest(BUCKETNAME);
            createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);
            ossClient.createBucket(createBucketRequest);
        }
        return ossClient;
    }

//    public static void main(String[] args) throws FileNotFoundException {
//        File file = new File("D:\\西点\\微信图片_20210902201640.jpg");
//        OSSClient ossClient = getOssClient();
//        ossClient.putObject(OssClientUtil.BUCKETNAME,"2.jpg",new FileInputStream(file));
//        ossClient.shutdown();
//    }
}
